/**
 * @program: LeetCode
 * @description: LeetCode : 剑指 Offer II 005. 单词长度的最大乘积
 * @author: WXY
 * @create: 2022-12-20 19:32
 * @Version 1.0
 **/

public class offer_two2_maxProduct {
    public static int maxProduct(String[] words) {
        int len = words.length;
        int[] arr = new int[len];
        for (int i = 0; i < len; i++) {
            String word = words[i];
            int wordLen = word.length();
            for (int j = 0; j < wordLen; j++) {
                arr[i] = arr[i] | (1 << (word.charAt(j) - 'a'));
            }
        }
        int max = 0;
        for (int i = 0; i < len; i++) {
            for (int j = i + 1; j < len; j++) {
                if ((arr[i] & arr[j]) == 0) {
                    max = Math.max(max, words[i].length() * words[j].length());
                }
            }
        }
        return max;
    }
}
